<template>
  <div class="member-center">
    <!-- 头部 -->
    <MemberHeader />
    <!-- /头部 -->
    <div class="my-integral">
      <div class="my-img">
        <img :src="userPic" v-if="userPic" alt />
        <img src="~/assets/images/buyer-img.png" v-if="!userPic" alt />
      </div>
      <div class="item current">
        <div class="number">{{scoreInfo.score}}</div>
        <div class="text">{{$t('myPoints.currentPoints')}}</div>
      </div>
      <div class="item">
        <div class="number">{{scoreInfo.expireScore}}</div>
        <div class="text">{{$t('myPoints.expiredPoints')}}</div>
      </div>
      <nuxt-link to="/user-center/uc-integral" class="record">
        <span class="icon"></span>
        <span class="text">{{$t('memberCenter.viewPointsDetails')}}</span>
        <span class="arr">&gt;&gt;</span>
      </nuxt-link>
    </div>
    <div class="content">
      <!-- 兑换列表 -->
      <div class="exchange-list">
        <div class="goods-list integral-list">
          <div class="list-con">
            <div
              class="item"
              v-for="item in scroeList"
              :key="item.prodId"
              @click="toScoreProdDet(item.prodId)"
            >
              <div class="goods-img">
                <img :src="item.pic" alt />
              </div>
              <div class="goods-msg">
                <div class="goods-name">{{item.prodName}}</div>
                <div class="goods-price">
                  <div class="icon">
                    <img src="~/assets/images/memberPic/integral-icon.png" alt />
                  </div>
                  <div class="integral-price">{{item.scorePrice}} {{$t('memberCenter.points')}}</div>
                  <div class="add" v-if="item.price>0">+</div>
                  <div class="price" v-if="item.price>0">￥{{item.price}}</div>
                </div>
                <div class="old-price">{{$t('memberCenter.marketPrice')}}￥{{item.oriPrice}}</div>
              </div>
            </div>
          </div>
          <!-- 商品列表为空 -->
          <div class="empty" v-if="!scroeList.length">
            <div class="img">
              <img src="~/assets/images/emptyPic/not-found.png" alt />
            </div>
            <div class="action">
              <div class="text">{{$t('sorryNoRelatedProducts')}}</div>
              <a href="/list" class="btn">{{$t('lookAtOther')}}</a>
            </div>
          </div>
          <!-- 商品列表为空 -->
        </div>
      </div>
      <!-- /兑换列表 -->
    </div>
  </div>
</template>

<script src='~/assets/js/load-transition'></script>
<script>
import MemberHeader from '~/components/member-header'
export default {
  layout: 'home',
  components: {
    MemberHeader
  },
  data () {
    return {
      scoreInfo: {},  //会员信息
      userPic: "",  //会员头像
      scroeList: []  //积分商品列表
    }
  },
  mounted () {
    // 设置网页标题
    document.title = this.$i18n.t('memberCenter.memberCenter')
    //积分信息
    this.$axios.get('/p/score/scoreInfo').then(({ data }) => {
      this.scoreInfo = data
    })

    // 获取会员头像
    this.$axios.get('/p/user/userInfo').then(({ data }) => {
      this.userPic = data.pic
    })

    //获取积分商品列表
    this.$axios.get('/p/score/prodScorePage').then(({ data }) => {
      this.scroeList = data.records
    })

  },
  methods: {
    // 跳转到积分商品详情
    toScoreProdDet (prodId) {
      this.$axios.get('/p/score/prodScorePage').then(({ data }) => {
        this.$router.push({ path: '/member-center/integral-det/' + prodId })
      })
    }
  }
}
</script>

<style scoped>
@import '~/assets/css/member-center.css';
@import '~/assets/css/integral-mall.css';
</style>
